var _excluded = ['className'];
function _extends() {
  _extends = Object.assign
    ? Object.assign.bind()
    : function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];
          for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
        return target;
      };
  return _extends.apply(this, arguments);
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
import { DatePicker as AntdDatePicker } from 'antd';
import 'antd/es/date-picker/style/index.js';
import classnames from 'classnames';
import React, { forwardRef } from 'react';
import { useFieldContext } from '../_utils/contexts/FieldContext';
import createField from '../createField';
/**
 * 日期选择框
 */
var DatePicker = /*#__PURE__*/ forwardRef(function (_ref, ref) {
  var className = _ref.className,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useFieldContext = useFieldContext(),
    label = _useFieldContext.label;
  return /*#__PURE__*/ React.createElement(
    AntdDatePicker,
    _extends(
      {
        placeholder: '\u8BF7\u9009\u62E9'.concat(label !== null && label !== void 0 ? label : ''),
        className: classnames('szzj-date-picker', className),
      },
      rest,
      {
        // @issue 组件内部暂不将 antd@4 的 Moment 类型提示切换到 Dayjs
        // @ts-ignore
        ref: ref,
      },
    ),
  );
});
var FormatMap = {
  default: 'YYYY-MM-DD',
  time: 'YYYY-MM-DD HH:mm:ss',
  year: 'YYYY',
  quarter: 'YYYY-\\QQ',
  month: 'YYYY-MM',
  week: 'YYYY-wo',
};
export default createField(DatePicker, {
  defaultDetailComponent: function defaultDetailComponent(_ref2) {
    var value = _ref2.value,
      format = _ref2.format,
      picker = _ref2.picker,
      showTime = _ref2.showTime;
    var formatByPicker = showTime
      ? FormatMap.time
      : picker && FormatMap[picker]
      ? FormatMap[picker]
      : FormatMap.default;
    var realFormat = format !== null && format !== void 0 ? format : formatByPicker;
    return /*#__PURE__*/ React.createElement(
      'span',
      null,
      typeof value === 'string' ? value : value ? value.format(realFormat) : '',
    );
  },
});
